define(function (require, exports, module) {
    var $ = require("zepto");
    module.exports = $;
    (function (t) {
        function e(t, e, n, i) {
            return Math.abs(t - e) >= Math.abs(n - i) ? t - e > 0 ? "Left" : "Right" : n - i > 0 ? "Up" : "Down"
        }
        function n() {
            u = null, h.last && (h.el.trigger("longTap"), h = {})
        }
        function i() {
            u && clearTimeout(u), u = null
        }
        function a() {
            s && clearTimeout(s), l && clearTimeout(l), c && clearTimeout(c), u && clearTimeout(u), s = l = c = u = null, h = {}
        }
        function o(t) {
            return("touch" == t.pointerType || t.pointerType == t.MSPOINTER_TYPE_TOUCH) && t.isPrimary
        }
        function r(t, e) {
            return t.type == "pointer" + e || t.type.toLowerCase() == "mspointer" + e
        }
        var s, l, c, u, d, h = {}, f = 750;
        t(document).ready(function () {
            var p, g, m, v, x = 0, b = 0;
            "MSGesture"in window && (d = new MSGesture, d.target = document.body), t(document).bind("MSGestureEnd", function (t) {
                var e = t.velocityX > 1 ? "Right" : -1 > t.velocityX ? "Left" : t.velocityY > 1 ? "Down" : -1 > t.velocityY ? "Up" : null;
                e && (h.el.trigger("swipe"), h.el.trigger("swipe" + e))
            }).on("touchstart MSPointerDown pointerdown", function (e) {
                (!(v = r(e, "down")) || o(e)) && (m = v ? e : e.touches[0], e.touches && 1 === e.touches.length && h.x2 && (h.x2 = void 0, h.y2 = void 0), p = Date.now(), g = p - (h.last || p), h.el = t("tagName"in m.target ? m.target : m.target.parentNode), s && clearTimeout(s), h.x1 = m.pageX, h.y1 = m.pageY, g > 0 && 250 >= g && (h.isDoubleTap = !0), h.last = p, u = setTimeout(n, f), d && v && d.addPointer(e.pointerId));
            }).on("touchmove MSPointerMove pointermove", function (t) {
                (!(v = r(t, "move")) || o(t)) && (m = v ? t : t.touches[0], i(), h.x2 = m.pageX, h.y2 = m.pageY, x += Math.abs(h.x1 - h.x2), b += Math.abs(h.y1 - h.y2))
            }).on("touchend MSPointerUp pointerup", function (n) {
                (!(v = r(n, "up")) || o(n)) && (i(), h.x2 && Math.abs(h.x1 - h.x2) > 30 || h.y2 && Math.abs(h.y1 - h.y2) > 30 ? c = setTimeout(function () {
                    h.el.trigger("swipe"), h.el.trigger("swipe" + e(h.x1, h.x2, h.y1, h.y2)), h = {};
                }, 0) : "last"in h && (30 > x && 30 > b ? l = setTimeout(function () {
                    var e = t.Event("tap");
                    e.cancelTouch = a, h.el.trigger(e), h.isDoubleTap ? (h.el && h.el.trigger("doubleTap"), h = {}) : s = setTimeout(function () {
                        s = null, h.el && h.el.trigger("singleTap"), h = {};
                    }, 250);
                }, 0) : h = {}), x = b = 0);
            }).on("touchcancel MSPointerCancel pointercancel", a), t(window).on("scroll", a);
        });
        ["swipe", "swipeLeft", "swipeRight", "swipeUp", "swipeDown", "doubleTap", "tap", "singleTap", "longTap"].forEach(function (e) {
            t.fn[e] = function (t) {
                return this.on(e, t);
            };
        });
    })($);
});